﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;

namespace IM.Net
{
    class SocketAsyncEventArgsPool
    {
        private Stack<SocketAsyncEventArgs> m_socketAsyncEventArgsPool;

        public  SocketAsyncEventArgsPool(Int32 nCapacity)
        {
            m_socketAsyncEventArgsPool = new Stack<SocketAsyncEventArgs>(nCapacity);
        }

        public int Count()
        {
            return m_socketAsyncEventArgsPool.Count;
        }

        public SocketAsyncEventArgs Pop()
        {
            lock (m_socketAsyncEventArgsPool)
            {
                return m_socketAsyncEventArgsPool.Pop();
            }
        }

        public int Push(SocketAsyncEventArgs socketArgs)
        {
            if (socketArgs == null)
            {
                return -1;
            }
            lock (m_socketAsyncEventArgsPool)
            {
                m_socketAsyncEventArgsPool.Push(socketArgs);
            }
            return 0;
        }
    }
}
